﻿using Fishing.Abstractions;
using Fishing.View;
using System;
using System.Windows;

namespace Fishing.Core
{
    public class DesktopCore : IDesktopCore
    {
        private Window? _faker;

        public void FakeWallpaper()
        {
            if (!MonitorHelper.IsMultiMonitor())
            {
                return;
            }
            
            _faker = new FakerView();

            _faker.Show();
            
            var monitor = MonitorHelper.GetSecondaryMonitor();

            SetFakerWallpaper(monitor);
        }

        public void Restore()
        {
            if (_faker != null)
            {
                Application.Current.Dispatcher.Invoke(() =>
                    _faker.Close());
            }
        }

        private void SetFakerWallpaper(IMonitor targetDisplay)
        {
            if (_faker is not null)
            {
                _faker.Left = Convert.ToDouble(targetDisplay.Bounds.X);
                _faker.Top = Convert.ToDouble(targetDisplay.Bounds.Y);
            }
        }
    }
}
